<template>
  <el-form :model="detailData" ref="ruleFormRef" :rules="rules" status-icon :label-position="labelPosition" label-width="120px" :inline="true" class="demo-form-inline">
    <el-form-item label="奖项名称">
      <el-input v-model="detailData.awardApplyName" disabled/>
    </el-form-item>
    <el-form-item label="奖项种类">
      <el-input v-model="detailData.applyClass" disabled/>
    </el-form-item>
    <el-form-item label="申报单位">
      <el-input v-model="detailData.applyUnitName" disabled/>
    </el-form-item>
    <el-form-item label="申报时间">
      <el-input v-model="detailData.applyTime" disabled/>
    </el-form-item>
    <el-form-item label="奖金标准(万元)">
      <el-input v-model="detailData.bonusStandard" disabled/>
    </el-form-item>
    <el-form-item label="奖金">
      <el-input v-model="detailData.bonus" disabled/>
    </el-form-item>
    <el-form-item label="备注">
      <el-input v-model="detailData.unitRemark" disabled/>
    </el-form-item>
  
  </el-form>
</template>
<script lang="ts">
import SelectOption from '@/views/science/components/selectOption/index.vue'
import { computed, reactive, ref, watch } from 'vue'
import { useStore } from 'vuex'
export default {
  components: {
    SelectOption,
  },
  emits: {
    valueFlag: null,
  },
  props:{
    detailData:{
      type:Object as any,
    }
  },
  setup(props, { emit }) {
    const store = useStore()
    const labelPosition = ref('right')
    const data = reactive({
      addUnit: false,
      innerValue: '',
      outsideValue: '',

      userAllList: computed(() => store.state.technologyStrength.userAllList),
      sexList: computed(() => store.state.technologyStrength.sexList),
      orgAllList: computed(() => store.state.technologyStrength.orgAllList),
      
      gjhLevelSelect: computed(() => store.state.technologyStrength.gjhLevelSelect),
      cooperateList: [],
      detailData : props.detailData
    })
   
    const form = reactive(store.state.technologyStrength.achievementINFO)

    watch(form, (newValue, oldValue) => {
      console.log("form值改变了")
      store.commit('technologyStrength/getachievementINFO', { ...form })
    });

    const rules = reactive({
      userName: [
        { required: true, message: '请选择姓名', trigger: 'change' },
      ],
      sex: [
        { required: true, message: '请选择性别', trigger: 'change', },
      ],
      unit: [
        { required: true, message: '请选择所属单位', trigger: 'change', },
      ],
      birthday:[
        { required: true, message: '请输入年龄', trigger: 'blur', },
      ],
      communicateClass: [
        { required: true, message: '请选择交流类别', trigger: 'change', },
      ],
      communicateStyle: [
        { required: true, message: '请选择交流方式', trigger: 'change', },
      ],
      communicateDate: [
        { required: true, message: '请选择交流时间', trigger: 'change' },
      ],
      detailInfo: [
        { required: true, message: '请输入详细信息', trigger: 'blur' },
      ],
    })
    
    const ruleFormRef = ref()
    const submitForm = async () => {
      await ruleFormRef.value.validate((valid, fields) => {
        if (valid) {
          emit('valueFlag', true)
          console.log('submit!')
        } else {
          emit('valueFlag', false)
        }
      })
    }

    const handleChangeDate = (val) => {
      const year = val.getFullYear(); // 获取年份
      const month = (val.getMonth() + 1) < 10 ? '0' + (val.getMonth() + 1) : (val.getMonth() + 1); // 获取月份，需要加1
      const day = val.getDate() < 10 ? '0' + val.getDate() : val.getDate(); // 获取日期
      const formattedDate = `${year}-${month}-${day}`;
      form.communicateDate = formattedDate
      store.commit('technologyStrength/gettalentInfo', { ...form })
    }


    return {
      labelPosition,
      data,
      form,
      rules,
      ruleFormRef,
      submitForm,
      handleChangeDate,
    }
  },
}
</script>
<style lang="scss" scoped>
.demo-form-inline .el-form-item {
  width: 48%;
}

:deep(.labelHeight .el-form-item__label) {
  line-height: 20px;
}

:deep(.el-date-editor.el-input) {
  width: 100%;
}

:deep(.el-date-editor.el-input__inner) {
  width: 100%;
}

:deep(.demo-form-inline .el-select) {
  width: 100%;
  margin: 0;
}

.el-select {
  width: 100%;
  margin: 0;
}

.selectLabel {
  width: 70%;
  min-height: 40px;
  line-height: 40px;
  padding: 0 15px;
  border: 1px solid #ccc;
  border-radius: 6px;
  display: inline-block;
}

.addLabel {
  display: inline-block;
  width: 120px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  background-color: #169bd5;
  border-radius: 6px;
  color: #fff;
  margin-left: 15px;
}

.unitBox {
  width: 100%;
  margin: 30px 0;

  .title {
    padding: 15px 0;
    border-bottom: 1px solid #ccc;
  }

  .tagBox {
    line-height: 40px;
    margin-top: 15px;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 10px 15px;
  }
}

.el-tag {
  margin-right: 10px;
}
</style>
  